//
//  PickerPageView.swift
//  SwiftUIDemo
//
//  Created by Kael on 2020/1/5.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct PickerPageView: View {
    
    @State var leftIndex = 0
    @State var rightIndex = 0
//    @ObjectBinding var server = DateServer()
    
    let leftResource = (0..<10).map{ $0%2 == 0 ? "🧜‍♀️\($0)" : "🧚‍♀️\($0)"}
    
    let rightResource = (11...36).map{ String($0 - 1,radix: $0).uppercased() }
    
    var body: some View {
        VStack{

            VStack{
                Text("Left value:")
                    .frame(width: 100, height: 60, alignment: .center)
                Text("\(self.leftResource[self.leftIndex])")
                    .padding(10)
                Picker(selection: $leftIndex, label: Text("Left Picker")) {
                    ForEach(0..<leftResource.count){
                        Text(self.leftResource[$0]).tag($0)
                    }
                }
                .background(Color.gray)
            }
            .padding(20)
            .background(Color.orange)
            
            VStack{
                Text("Left value:")
                    .background(Color.red)
                Text("\(self.rightResource[self.rightIndex])")
                        .padding(10)

                
                Picker(selection: $rightIndex, label: Text("Right Picker")) {
                    ForEach(0..<leftResource.count){
                        Text(self.rightResource[$0]).tag($0)
                    }
                }
                .background(Color.gray)

            }
            .padding(20)
            .background(Color.orange)
    
        }
        .navigationBarTitle(Text("picker"))
    }
}

struct PickerPageView_Previews: PreviewProvider {
    static var previews: some View {
        PickerPageView()
    }
}
